home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 May / macformat-050.iso / Shareware Plus / Developers / Find_icon folder / Sources / DTGetIconSuite.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-25  |  3.2 KB  |  127 lines  |  [TEXT/CWIE]

  1. /*    ---------------------------------------------------------------------------------------------
  2.     Find_icon, code for constructing icon suites for files and folders
  3.     
  4.     by James W. Walker
  5.     preferred e-mail: <mailto:jwwalker@kagi.com>
  6.     alternate e-mail: <mailto:jwwalker@aol.com>, <jim@nisus-soft.com>
  7.     web: <http://users.aol.com/jwwalker/>
  8.     
  9.     File: DTGetIconSuite.c
  10.     
  11.     Copyright ©1997 by James W. Walker
  12.     
  13.     You may incorporate this sample code into your applications without
  14.     restriction, though the sample code has been provided "AS IS" and the
  15.     responsibility for its operation is 100% yours.
  16.     If you're going to re-distribute the source, please make it clear
  17.     that the code was descended from James W. Walker's code,
  18.     but that you've made changes.
  19.     ---------------------------------------------------------------------------------------------
  20. */
  21. #include <Errors.h>
  22. #include "MoreDesktopMgr.h"
  23. #include "cheap-exceptions.h"
  24. #include "DTGetIconSuite.h"
  25.  
  26.  
  27. typedef struct {
  28.     OSType    fileCreator;
  29.     OSType    fileType;
  30.     short    vRefNum;
  31.     Boolean    no_mask;
  32. } DTAddingData;
  33.  
  34. static    short ResIconToDTIcon( OSType iconType )
  35. {
  36.     short    DT_type;
  37.     
  38.     switch (iconType)
  39.     {
  40.         case large1BitMask:
  41.             DT_type = kLargeIcon;
  42.             break;
  43.         case large4BitData:
  44.             DT_type = kLarge4BitIcon;
  45.             break;
  46.         case large8BitData:
  47.             DT_type = kLarge8BitIcon;
  48.             break;
  49.         case small1BitMask:
  50.             DT_type = kSmallIcon;
  51.             break;
  52.         case small4BitData:
  53.             DT_type = kSmall4BitIcon;
  54.             break;
  55.         case small8BitData:
  56.             DT_type = kSmall8BitIcon;
  57.             break;
  58.         default:
  59.             DT_type = 0;
  60.             break;
  61.     }
  62.     return DT_type;
  63. }
  64.  
  65. /*****************************************************************************/
  66.  
  67. static pascal OSErr    AddOneDTIcon(
  68. /* --> */    ResType theType,
  69. /* <-> */    Handle *theIcon,
  70. /* <-> */    DTAddingData *data )
  71. {
  72.     OSErr    error;
  73.     
  74.     error = DTGetIcon( NULL, data->vRefNum, ResIconToDTIcon( theType ),
  75.         data->fileCreator, data->fileType, theIcon );
  76.     
  77.     if ( (error == noErr) && ( (theType == 'ICN#') || (theType == 'ics#') ) )
  78.     {
  79.         data->no_mask = false;
  80.     }
  81.     
  82.     return error;
  83. }
  84.  
  85. /*****************************************************************************/
  86.  
  87. pascal    OSErr    DTGetIconSuite(
  88. /* --> */    short vRefNum,
  89. /* --> */    IconSelectorValue iconTypes,
  90. /* --> */    OSType fileCreator,
  91. /* --> */    OSType fileType,
  92. /* <-- */    Handle *iconSuite)
  93. {
  94.     OSErr    error;
  95.     IconActionUPP    add_DB_icon_UPP;
  96.     DTAddingData    adding_data;
  97.     
  98.     // DTGetIcon doesn't know about mini icons, and returns paramErr
  99.     // if you ask for one.  But I don't want that to cause our
  100.     // suite construction to fail.  So, just make sure that
  101.     // DTGetIcon is never asked for mini icons.
  102.     iconTypes &= ~kSelectorAllMiniData;
  103.     
  104.     error = NewIconSuite( iconSuite );
  105.     if (error == noErr)
  106.     {
  107.         add_DB_icon_UPP = NewIconActionProc( AddOneDTIcon );
  108.         require_action( add_DB_icon_UPP, NewIconActionProc, error = memFullErr );
  109.         adding_data.no_mask = true;
  110.         adding_data.fileCreator = fileCreator;
  111.         adding_data.fileType = fileType;
  112.         adding_data.vRefNum = vRefNum;
  113.         
  114.         error = ForEachIconDo( *iconSuite, iconTypes,
  115.             add_DB_icon_UPP, &adding_data );
  116.         
  117.         DisposeRoutineDescriptor( add_DB_icon_UPP );
  118.     NewIconActionProc:
  119.         if ( (error == noErr) && adding_data.no_mask )
  120.         {
  121.             error = noMaskFoundErr;
  122.         }
  123.     }
  124.     
  125.     return error;
  126. }
  127.